package com.lyn.system.controller;

import com.feizhou.swagger.annotation.ApiOperation;
import com.feizhou.swagger.annotation.Param;
import com.feizhou.swagger.annotation.Params;
import com.lyn.common.base.BaseController;
import com.lyn.common.base.Result;
import com.lyn.system.service.UserService;

public class UserController extends BaseController {

    UserService srv = UserService.me;

    @ApiOperation(url = "/insert", httpMethod = "post", description = "新增用户信息")
    @Param(name = "data", description = "新增用户信息", required = true, dataType = "string")
    public void insert() {
        Result result = srv.insert(getPara("data"));
        renderJson(result);
    }

    @ApiOperation(url = "/updateById", httpMethod = "put", description = "根据主键更新单个用户的信息")
    @Param(name = "data", description = "更新单个用户的信息", required = true, dataType = "string")
    public void updateById() {
        Result result = srv.updateById(getPara("data"));
        renderJson(result);
    }

    @ApiOperation(url = "/updatesById", httpMethod = "put", description = "根据主键更新多个用户的信息")
    @Param(name = "data", description = "更新多个用户的信息", required = true, dataType = "string")
    public void updatesById() {
        Result result = srv.updatesById(getPara("data"));
        renderJson(result);
    }

    @ApiOperation(url = "/customUpdate", httpMethod = "put", description = "自定义条件更新用户信息")
    @Param(name = "data", description = "自定义条件更新用户信息", required = true, dataType = "string")
    public void customUpdate() {
        Result result = srv.customUpdate(getPara("data"));
        renderJson(result);
    }

    @ApiOperation(url = "/getById", httpMethod = "get", description = "获取单个用户的信息")
    @Param(name = "id", description = "获取单个用户的信息", required = true, dataType = "string")
    public void getById() {
        int id = getParaToInt("id");
        Result result = srv.getById(id);
        renderJson(result);
    }

    @ApiOperation(url = "/customGet", httpMethod = "get", description = "自定义条件查询用户的信息")
    @Params({@Param(name = "userId", description = "用户登录名", required = true, dataType = "string"),
            @Param(name = "email", description = "邮箱", required = true, dataType = "string")})
    public void customGet() {
        String userId = getPara("userId");
        String email = getPara("email");
        Result result = srv.customSelect(userId, email);
        renderJson(result);
    }

    @ApiOperation
    @Params({@Param(name = "pageNumber", description = "页码", required = true, dataType = "Integer"),
            @Param(name = "pageSize", description = "每页多少行", required = true, dataType = "Integer"),
            @Param(name = "email", description = "邮箱", required = true, dataType = "string")})
    public void getByPages() {
        int pageNumber = getParaToInt("pageNumber");
        int pageSize = getParaToInt("pageSize");
        String email = getPara("email");
        Result result = srv.getByPage(pageNumber, pageSize, email);
        renderJson(result);
    }
}
